home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / STDLIB.PAK / STRING.CPP < prev    next >
Text File  |  1997-05-06  |  958b  |  37 lines

  1.  #include <string>
  2.  
  3.  using namespace std;
  4.  
  5.  int main ()
  6.  {
  7.    string test, result;
  8.    //
  9.    // Type in a string over five characters long.
  10.    //
  11.    while (test.empty() ||  test.size() <= 5)
  12.    {
  13.      cout << "Type a string between 5 and 100 characters long. " << endl;
  14.      cin >> test;
  15.    }
  16.    //
  17.    // Test operator[] access.
  18.    //
  19.    cout << endl << "You typed in: " << test << endl << endl;
  20.    cout << "Changing the third character from " << test[2] << " to * " << endl;
  21.    test[2] = '*';
  22.    cout << "now its: " << test << endl << endl;
  23.    //
  24.    // Try the insertion member function.
  25.    //
  26.    test.insert(test.size() / 2, "(the middle is here!)");
  27.    cout << "Identifying the middle: " << test << endl << endl;
  28.    //
  29.    // Try replacement.
  30.    //
  31.    test.replace(test.find("middle",0), 6, "center");
  32.    cout << "I didn't like the word 'middle', so instead, I'll say: "
  33.         << endl << test << endl;
  34.  
  35.    return 0;
  36.  }
  37.